
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layuiAdmin 后台管理员</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="__STATIC__/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="__STATIC__/layuiadmin/style/admin.css" media="all">
</head>
<body>
<!--
 * @Author: 小悟空56
 * @Date: 2022-02-28 14:08:20
 * @LastEditTime: 2022-02-28 14:29:49
 * @LastEditors: 小悟空56
 * @Description: 描述：
 * @FilePath: \copy.copy.com\app\admin\view\login_log\index.html
 * 白月光
-->
<div class="layui-fluid">
  <div class="layui-card">

    <div class="layui-form layui-card-header layuiadmin-card-header-auto">


        <div class="layui-inline">
          <label class="layui-form-label">登录日志</label>
          <div class="layui-input-block">

            <select name="username">
              <option value="">All</option>
              {volist name="arr" id="v"}
               
                <option value="{$v.username}" selected>{$v.username}</option>
               
              {/volist}
            </select>

          </div>
        </div>

        <div class="layui-inline">
          <label class="layui-form-label">时间</label>
          <div class="layui-input-block" style="width: 300px;">
            <input type="text" name="time" class="layui-input" id="test10" autocomplete="off" placeholder=" Y-M-d H:i:s ">
          </div>
        </div>


        <div class="layui-inline">
          <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
          </button>
        </div>
      </div>

    </div>

    <div class="layui-card-body">

      <table id="LAY-user-back-manage" lay-filter="LAY-user-back-manage"></table>


     

     

      <script type="text/html" id="table-useradmin-admin">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
      </script>

    </div>
  </div>
</div>

<script src="__STATIC__/layuiadmin/layui/layui.js"></script>
<script>
  layui.config({
    base: '__STATIC__/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table','laydate'], function(){
    var $ = layui.$
            ,form = layui.form
            ,laydate = layui.laydate
            ,table = layui.table;


    //日期时间范围
    laydate.render({
      elem: '#test10'
      ,type: 'datetime'
      ,range: true
    });

    table.render({
      elem: '#LAY-user-back-manage'
      ,url:'loginLogList'
      // ,method:"post"
      ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
      ,title: '用户数据表'
      ,cols: [[
        { title:'ID', fixed: 'left', type:'numbers'},
        {field:'id', hide: true}
        ,{field:'username', title:'用户名'}
        ,{field:'ip', title:'IP'}
        ,{field:'province', title:'省份' }
        ,{field:'city', title:'城市' }
        ,{field:'equipment', title:'登录设备'}
        ,{field:'create_time', title:'时间' }
        ,{fixed: 'right', title:'操作', toolbar: '#table-useradmin-admin', width:100}
      ]]
      ,page: true
       // 排序（倒序）输出
       ,initSort:{
           field:'id'
          ,type:'desc'
       }
       ,limits: [2,5,10]  //一页选择显示3,5或10条数据
       ,limit:10
         // 解决layui分页数据不变的情况
            // https://blog.csdn.net/qq_35077107/article/details/101168088
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
                        var result;
                        console.log(this);
                        console.log(JSON.stringify(res));
                        if(this.page.curr){
                            result = res.data.slice(this.limit*(this.page.curr-1),this.limit*this.page.curr);
                        }
                        else{
                            result=res.data.slice(0,this.limit);
                        }
                        return {
                            "code": res.code, //解析接口状态
                            "msg": res.msg, //解析提示文本
                            "count": res.count, //解析数据长度
                            "data": result //解析数据列表
                        };
                    }
             // 解决layui分页数据不变的情况

    });

     //监听搜索
     form.on('submit(LAY-user-back-search)', function(data){
      var field = data.field;
      console.log(field);
      //执行重载
      table.reload('LAY-user-back-manage', {
        where: field
      });
    });

    //监听行工具事件
    table.on('tool(LAY-user-back-manage)', function(obj){
      var data = obj.data;
      console.log(data.id);
      if(obj.event === 'del'){
        layer.confirm('确认删除该条信息吗？删除后将无法返回！', function(index){
          $.ajax({
            type: "GET",
            url:'delLoginLog',
            data:{'id':data.id},
            dataType:"json",
            success:function (res) {
              // console.log(res);
              if (res['code']==1){
                layer.msg(res['msg'],{icon: 1,time: 1000 },function () {
                  obj.del();
                  layer.close(index);
                  table.reload('LAY-user-back-manage');
                });
              }
            }
          });


        });
      } else if(obj.event === 'edit'){
        //iframe层-父子操作
        // console.log(data);
        layer.open({
          type: 2,
          area: ['450px', '700px'],
          fixed: false, //不固定
          maxmin: true,
          content: 'edit?id='+data.id,
          btn: ['确定', '取消'],
          yes: function(index, layero){
            var iframeWindow = window['layui-layer-iframe'+ index]
                    ,submit = layero.find('iframe').contents().find("#LAY-user-back-submit");
            //监听提交
            iframeWindow.layui.form.on('submit(LAY-user-back-submit)', function(data){
              var field = data.field; //获取提交的字段

              //提交 Ajax 成功后，静态更新表格中的数据
              //loading层
              var index1 = layer.load(1, {
                shade: [0.1,'#fff'], //0.1透明度的白色背景
                time: 1000
              });
              $.ajax({
                url:'update',
                type:"POST",
                data:field,
                dataType:"json",
                success:function (res) {
                  console.log(res['code']);
                  if (res['code'] == 1){
                    layer.msg(res['msg'],{icon: 1,time: 1000 },function () {
                      table.reload('LAY-user-back-manage');
                      layer.close(index1); //关闭弹层
                      layer.close(index); //关闭弹层
                    });
                  }
                }
              });
            });
            submit.trigger('click');
          },
          btn2: function(){
            layer.closeAll();
          }
        });
      }
    });


  });
</script>
</body>
</html>

